package com.tian.recycler.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import androidx.databinding.DataBindingUtil
import androidx.navigation.NavController
import androidx.navigation.Navigation
import com.tian.recycler.R
import com.tian.recycler.databinding.FragmentMainBinding


/**
 * @author tiansongtao,Email:769001510@qq.com, created on 2021/3/18 16:17
 *
 */
class MainFragment : Fragment(), AdapterView.OnItemClickListener {


    private lateinit var b: FragmentMainBinding
    private val navController: NavController by lazy { Navigation.findNavController(requireActivity(), R.id.nav_host_fragment) }

    private val data = listOf(
            "item show Anim",
            "item 添加动画",
            "item touch"
    )

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        b = DataBindingUtil.inflate(inflater, R.layout.fragment_main, container, false)
        b.lvNav.adapter = ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, this.data)
        b.lvNav.onItemClickListener = this
        return b.root
    }

    override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
        when (position) {
            0 -> navController.navigate(R.id.action_main_fragment_to_item_show_anim_fragment)
            1 -> navController.navigate(R.id.action_main_fragment_to_item_add_anim_fragment)
            2 -> navController.navigate(R.id.action_main_fragment_to_item_touch_fragment)
        }
    }


}